home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Graphics / QD3D / WorldRayPickSample / Source / WRay_Menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  5.8 KB  |  393 lines  |  [TEXT/CWIE]

  1. /* 
  2.  *    WRay_Menu.c
  3.  *
  4.  *    QuickDraw 3D 1.6 Sample
  5.  *    Robert Dierkes
  6.  *
  7.  *     07/28/98    RDD        Created.
  8.  */
  9.  
  10. /*------------------*/
  11. /*    Include Files    */
  12. /*------------------*/
  13. #include "QD3D.h"
  14.  
  15. #if defined(OS_MACINTOSH) && OS_MACINTOSH
  16. #include <Devices.h>
  17. #include <Menus.h>
  18. #include <Dialogs.h>
  19. #include <Resources.h>
  20. #include <ToolUtils.h>
  21. #endif
  22.  
  23. #include "WRay_Error.h"
  24. #include "WRay_Document.h"
  25. #include "WRay_Main.h"
  26. #include "WRay_Menu.h"
  27. #include "WRay_Pick.h"
  28. #include "WRay_Scene.h"
  29. #include "WRay_System.h"
  30.  
  31.  
  32. /*------------------*/
  33. /*      Constants        */
  34. /*------------------*/
  35. #define    kMenuBarRsrcID        128
  36. #define    kAboutDialogRsrcID    128
  37.  
  38.  
  39. /*----------------------*/
  40. /*    Extern Declarations    */
  41. /*----------------------*/
  42. extern    TQ3Boolean    gTimeToQuit;
  43.  
  44.  
  45. /*----------------------*/
  46. /*    Global Declarations    */
  47. /*----------------------*/
  48. Handle        ghMenuBar = NULL;
  49.  
  50.  
  51. /*----------------------*/
  52. /*   Local Prototypes   */
  53. /*----------------------*/
  54. static
  55. TQ3Boolean Menu_Apple(
  56.             short            menuID,
  57.             short            itemNumber);
  58. static
  59. TQ3Boolean Menu_File(
  60.             short            itemNumber,
  61.             TDocumentPtr    pDoc);
  62. static
  63. TQ3Boolean Menu_Edit(
  64.             short            itemNumber,
  65.             TDocumentPtr    pDoc);
  66. static
  67. TQ3Boolean Menu_WorldRay(
  68.             short            menuID,
  69.             short            itemNumber,
  70.             TDocumentPtr    pDoc);
  71. static
  72. TQ3Boolean    Menu_AboutBox (
  73.             void);
  74.  
  75.  
  76.  
  77. /*
  78.  *    Menu_Initialize
  79.  */
  80. TQ3Boolean Menu_Initialize(
  81.             void)
  82. {
  83.     TQ3Boolean        goodMenus;
  84.  
  85.     goodMenus = kQ3True;
  86.  
  87.     /* Initialize MenuBar */
  88.     ghMenuBar = GetNewMBar (kMenuBarRsrcID);
  89.     if (ghMenuBar != NULL) {
  90.         SetMenuBar(ghMenuBar);
  91.         AppendResMenu(GetMenuHandle (mApple), (ResType) 'DRVR');
  92.         DrawMenuBar();
  93.     }
  94.     else {
  95.         ERROR_DEBUG_STR ("Menu_Initialize: Menu_Initialize: Couldn't find menu bar.");
  96.         ghMenuBar = NULL;
  97.         goodMenus = kQ3False;
  98.     }
  99.  
  100.      return (goodMenus);
  101. }
  102.  
  103.  
  104. /*
  105.  *    Menu_InitializeItems
  106.  *
  107.  *    Globals:
  108.  *        None
  109.  *
  110.  *    Menu_InitializeItems sets menu items based on these pDoc fields:
  111.  */
  112. TQ3Boolean Menu_InitializeItems(
  113.             TDocumentPtr    pDoc)
  114. {
  115.     MenuHandle        hMenu;
  116.  
  117.     #pragma unused(pDoc)
  118.  
  119.     DEBUG_ASSERT(pDoc != NULL, Menu_InitializeItems);
  120.  
  121.     /*
  122.      * mRay Menu
  123.      */
  124.     hMenu = GetMenuHandle(mRay);
  125.     DEBUG_ASSERT(hMenu != NULL, Menu_InitializeItems);
  126.     if (hMenu == NULL) {
  127.         return kQ3False;
  128.     }
  129.  
  130.     DisableItem(hMenu, iRayEnd);
  131.     CheckItem(hMenu, iRayRotate, Scene_IsRotating());
  132.     CheckItem(hMenu, iRaySound, System_GetSound());
  133.  
  134.     return kQ3True;
  135. }
  136.  
  137.  
  138. /*
  139.  *    Menu_Command
  140.  */
  141. TQ3Boolean Menu_Command (
  142.         long            menuResult,
  143.         TDocumentPtr    pDoc)
  144. {
  145.     TQ3Boolean    isOK = kQ3True;
  146.     short        menuID,
  147.                 itemNumber;
  148.  
  149.     if (menuResult == 0) {
  150.         return kQ3False;
  151.     }
  152.  
  153.     menuID       = HiWord (menuResult);
  154.     itemNumber = LoWord (menuResult);
  155.  
  156.     switch (menuID) {
  157.         case mApple:
  158.             isOK = Menu_Apple(menuID, itemNumber);
  159.             break;
  160.  
  161.         case mFile:
  162.             isOK = Menu_File(itemNumber, pDoc);
  163.             break;
  164.  
  165.         case mEdit:
  166.             isOK = Menu_Edit(itemNumber, pDoc);
  167.         break;
  168.  
  169.         case mRay:
  170.             isOK = Menu_WorldRay(menuID, itemNumber, pDoc);
  171.         break;
  172.  
  173.         default:
  174.             isOK = kQ3False;
  175.             break;
  176.  
  177.     }  /*  switch (menuID)  */
  178.  
  179.     HiliteMenu (0);
  180.  
  181.     return isOK;
  182. }
  183.  
  184.  
  185. #pragma mark -
  186.  
  187. /*
  188.  *    Menu_Apple
  189.  */
  190. static
  191. TQ3Boolean Menu_Apple(
  192.         short            menuID,
  193.         short            itemNumber)
  194. {
  195.     TQ3Boolean    isOK = kQ3True;
  196.  
  197.     switch (itemNumber)
  198.     {
  199.     case iAbout:
  200.         isOK = Menu_AboutBox();
  201.         break;
  202.  
  203.     default:
  204.         {
  205.             MenuHandle    hMenu;
  206.             Str255        deskAccName;
  207.             GrafPtr        oldPort;
  208.  
  209.             hMenu = GetMenuHandle (menuID);
  210.             if (hMenu != NULL) {
  211.                 GetPort (&oldPort);
  212.  
  213.                 GetMenuItemText (hMenu, itemNumber, deskAccName);
  214.                 (void) OpenDeskAcc (deskAccName);
  215.                 SetPort (oldPort);
  216.             }
  217.             else {
  218.                 isOK = kQ3False;
  219.             }
  220.         }
  221.         break;
  222.     }
  223.  
  224.     return isOK;
  225. }
  226.  
  227.  
  228. /*
  229.  *    Menu_File
  230.  */
  231. static
  232. TQ3Boolean Menu_File(
  233.         short            itemNumber,
  234.         TDocumentPtr    pDoc)
  235. {
  236.     TQ3Boolean    isOK = kQ3True;
  237.  
  238.     #pragma unused(pDoc)
  239.  
  240.     switch (itemNumber) {
  241.     case iNew:
  242.     case iOpen:
  243.     case iClose:
  244.     case iSave:
  245.     case iSaveAs:
  246.         isOK = kQ3False;/**/
  247.         break;
  248.  
  249.     case iQuit:
  250.         gTimeToQuit = kQ3True;
  251.         break;
  252.  
  253.     default:
  254.         System_Beep();
  255.         isOK = kQ3False;
  256.         break;
  257.     }
  258.  
  259.     return isOK;
  260. }
  261.  
  262.  
  263. /*
  264.  *    Menu_Edit
  265.  */
  266. static
  267. TQ3Boolean Menu_Edit(
  268.         short            itemNumber,
  269.         TDocumentPtr    pDoc)
  270. {
  271.     TQ3Boolean        isOK = kQ3True;
  272.  
  273.     #pragma unused (pDoc)
  274.  
  275.     if (! SystemEdit (itemNumber - 1)) {
  276.         switch (itemNumber) {
  277.         case iUndo:        break;
  278.         case iCut:        break;
  279.         case iCopy:        break;
  280.         case iPaste:    break;
  281.         case iClear:    break;
  282.         }
  283.     }
  284.  
  285.     return isOK;
  286. }
  287.  
  288.  
  289. /*
  290.  *    Menu_WorldRay
  291.  */
  292. static
  293. TQ3Boolean Menu_WorldRay(
  294.         short            menuID,
  295.         short            itemNumber,
  296.         TDocumentPtr    pDoc)
  297. {
  298.     TQ3Boolean        isOK = kQ3False;
  299.     MenuHandle        hMenu;
  300.  
  301.     DEBUG_ASSERT(pDoc != NULL, Menu_WorldRay);
  302.  
  303.     hMenu = GetMenuHandle(menuID);
  304.     DEBUG_ASSERT(hMenu != NULL, Menu_WorldRay);
  305.     if (hMenu == NULL) {
  306.         return kQ3False;
  307.     }
  308.  
  309.     switch (itemNumber) {
  310.  
  311.     case iRayBegin:
  312.         {
  313.             if (Pick_BeginAnimation(pDoc) == kQ3Success) {
  314.                 DisableItem(hMenu, iRayBegin);
  315.                 EnableItem(hMenu,  iRayEnd);
  316.                 isOK = kQ3True;
  317.             } else {
  318.                 isOK = kQ3False;
  319.             }
  320.         }
  321.         break;
  322.  
  323.     case iRayEnd:
  324.         {
  325.             if (Pick_EndAnimation(pDoc) == kQ3Success) {
  326.                 EnableItem(hMenu,  iRayBegin);
  327.                 DisableItem(hMenu, iRayEnd);
  328.                 isOK = kQ3True;
  329.             } else {
  330.                 isOK = kQ3False;
  331.             }
  332.         }
  333.         break;
  334.  
  335.     case iRayRotate:
  336.         {
  337.             CheckItem(hMenu, itemNumber, ! Scene_IsRotating());
  338.             Scene_SetIsRotating((Scene_IsRotating() == kQ3True) ? kQ3False : kQ3True);
  339.             isOK = kQ3True;
  340.         }
  341.         break;
  342.  
  343.     case iRaySound:
  344.         {
  345.             TQ3Boolean    itemState;
  346.  
  347.             itemState = System_GetSound() ? kQ3False : kQ3True;
  348.             CheckItem(hMenu, itemNumber, itemState);
  349.             System_SetSound(itemState);
  350.             isOK = kQ3True;
  351.         }
  352.         break;
  353.  
  354.     default:
  355.         {
  356.             System_Beep();
  357.             isOK = kQ3False;
  358.         }
  359.         break;
  360.     }
  361.  
  362.     return isOK;
  363. }
  364.  
  365.  
  366.  
  367. #pragma mark -
  368.  
  369. /*
  370.  *    Menu_AboutBox
  371.  */
  372. static
  373. TQ3Boolean Menu_AboutBox (void)
  374. {
  375.     TQ3Boolean    isOK = kQ3True;
  376.     DialogPtr    theDialog;
  377.     short        itemHit;
  378.  
  379.     theDialog = GetNewDialog(kAboutDialogRsrcID, NULL, kWindowOnTop);
  380.     if (theDialog == NULL)
  381.         return kQ3False;
  382.  
  383.     do {
  384.         ModalDialog (NULL, &itemHit);
  385.     }
  386.     while (itemHit != ok);
  387.  
  388.     DisposeDialog (theDialog);
  389.  
  390.     return isOK;
  391. }
  392.  
  393.